<?php

use app\common\services\StaticServices;
use yii\helpers\Url;

?>

<?= Yii::$app->view->renderFile('@app/modules/admin/views/common/tab_calendar.php', ['tab' => 'set']) ?>
<div class="ui equal width grid">
  <div class="column">
    <div class="panel">
      <div class="panel-alone-content">
        <form class="ui form">
          <div class="field">
            <label>具体日期:</label>
            <input type="text" name="date-value" placeholder="20190101"
                   value="<?= isset($info['date_value']) ? $info['date_value'] : '' ?>">
          </div>
          <div class="field">
            <label>日期标签名称:</label>
            <input type="text" name="date-name" placeholder=""
                   value="<?= isset($info['data_name']) ? $info['data_name'] : '' ?>">
          </div>
          <div class="field">
            <label>证券史上的今天:</label>
            <textarea id="date_history_today"><?= isset($info['history_today']) ? $info['history_today'] : '' ?></textarea>
          </div>
          <div class="field">
            <label>营销机会:</label>
            <textarea id="date_marketing"><?= isset($info['marketing']) ? $info['marketing'] : '' ?></textarea>
          </div>
          <div class="field">
            <label>昊视专栏:</label>
            <input onchange="previewImage()" type="file"  name="image_url"  id="image_url" class="input-file">
            <div id="preview" >
              <?php if(!empty($info['image_url'])):?>
                <img style="width:120px;height:120px;padding-top: 10px;" src="<?= $info['image_url']?>"/>
              <? endif;?>
            </div>
          </div>
          <input type="hidden" class="image_url" >
          <input type="hidden" name="_csrf" id='csrf' value="<?= Yii::$app->request->csrfToken ?>">
          <input type="hidden" name="calendar-id" value="<?= isset($info['id']) ? $info['id'] : 0 ?>">
          <button class="ui green basic button calendar-save"  style="z-index:9999"  type="button">提交</button>
        </form>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript">
  //预览
  function previewImage(){
    var _csrf = $("#csrf").val()
    var formData = new FormData();
    formData.append("image_url",$("#image_url")[0].files[0]);
    $.ajax({
      url: '/admin/calendar/upload',
      type:'post',
      dataType: 'json',
      data: formData,
      contentType: false,
      processData: false,

      success: function (res) {
        if (res.code == 200) {
          $("#preview").html('<img style="width:120px;height:120px;;padding-top: 10px;" src="' + res.data + '"/>');
          $(".image_url").val(res.data);
        }
      }
    })

  }
  require(['modules/calendar/set'], function (set) {
    set.cal_set()
  })
</script>